package com.ruoyi.group.service.impl;

import com.ruoyi.group.domain.RpCommunication;
import com.ruoyi.group.domain.dto.DeptOrderDto;
import com.ruoyi.group.domain.dto.OrderDetailsDto;
import com.ruoyi.group.mapper.OrderDetailsMapper;
import com.ruoyi.group.service.OrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author:黄志超
 * @Todo:TODO
 * @DateTime:2022/3/16 17:16
 * @Component:蜗牛
 **/
@Service
@SuppressWarnings("ALL")
public class OrderDetailsServiceImpl  implements OrderDetailsService {

    @Resource
    OrderDetailsMapper detailsMapper;

    @Override
    public DeptOrderDto findAll(String orderNO, Integer userid) {

      return detailsMapper.findAll(userid,orderNO);

    }

    @Override
    public boolean subCommunication(RpCommunication rpCommunication) {
        //得到当前的工单号
        String order = rpCommunication.getOrder();
        //得到当前工单对应的工单id
        int userOrderid = detailsMapper.queryOrder(order);

        //放入时间
        rpCommunication.setCreateTime(new Date());

        rpCommunication.setUpdateTime(new Date());

        rpCommunication.setIsdeleted(1);
        //插入当前工单号到聊天沟通中间表去
         int  rp= detailsMapper.subCommunication(rpCommunication);

        //得到返回的自增长用户ID
        Integer communicationId = rpCommunication.getCommunicationId();

        //插入当前工单号到聊天沟通中间表去和返回的自增长id一起插入中间表
        int i1 = detailsMapper.insertOrder(userOrderid, communicationId);

        return i1>0;
    }

    @Override
    public List<RpCommunication> findKeeperOrder(String orderNO) {
        List<RpCommunication> keeperOrder = detailsMapper.findKeeperOrder(orderNO);
        return keeperOrder;

    }
}
